package com.aysafety.iotdataplatformweb.controller.geosound;

import com.aysafety.core.common.CheckUtils;
import com.aysafety.core.common.DataConversionUtil;
import com.aysafety.core.common.DateUtils;
import com.aysafety.iotdataplatformweb.controller.base.BaseController;
import com.aysafety.iotdataplatformweb.services.geosound.GeoSoundService;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController @RequestMapping("/api/mineMonitor/realMonitor/earthSound") public class GeoSoundController
    extends BaseController {

    private Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired private GeoSoundService geoSoundService;

    @RequestMapping("/getEnergyData")
    public Map<String, Object> getEnergyData(@RequestParam Map<String, Object> params, HttpServletRequest request,
        HttpServletResponse response) {
        try {
            Map<String, Object> data = new HashMap<String, Object>();
            // 矿区id
            String mineId = DataConversionUtil.getStrFromMap("mineId", params);

            String equipmentId = DataConversionUtil.getStrFromMap("equipmentId", params);
            // 开始时间
            String startTime = DataConversionUtil.getStrFromMap("startTime", params);


            if (StringUtils.isBlank(mineId) || StringUtils.isBlank(equipmentId) || StringUtils.isBlank(startTime)) {
                return this.formatReturnData("缺少参数");
            }

            if (!CheckUtils.isValidDate(startTime, "yyyy-MM-dd HH:mm:ss")) {
                return this.formatReturnData("日期格式不正确");
            }
            // 结束时间
            String defaultEndTime = DateUtils.getCurrentTime("yyyy-MM-dd HH:mm:ss");
            String endTime = DataConversionUtil.getStrFromMapOrSetDefaultValue("endTime", defaultEndTime, params);

            String timeSpanStr = DataConversionUtil.getStrFromMapOrSetDefaultValue("timeSpan", "0", params);
            int timeSpan = Integer.parseInt(timeSpanStr);

            String timeUnit = DataConversionUtil.getStrFromMapOrSetDefaultValue("timeUnit", "s", params);

            String pageStr = DataConversionUtil.getStrFromMapOrSetDefaultValue("page", "0", params);
            int page = Integer.parseInt(pageStr);

            String startRow = DataConversionUtil.getStrFromMapOrSetDefaultValue("startRow", "", params);

            String firstStartRow = DataConversionUtil.getStrFromMapOrSetDefaultValue("firstStartRow", "", params);

            List<Map<String, Object>> result = null;
            if (endTime == defaultEndTime) {
                result = geoSoundService.queryRealTimeByGeoSound(mineId, equipmentId, startTime, endTime, timeSpan, timeUnit, page, 7200,
                                startRow);
            } else {
                result = geoSoundService
                        .queryRealTimeByGeoSound(mineId, equipmentId, startTime, endTime, timeSpan, timeUnit, page, 0,
                                startRow);
            }
            //data.put("total",geoSoundService.countByGeoSound(mineId, equipmentId, startTime, endTime, timeSpan, timeUnit));
            data.put("total", result.size());
            data.put("list", result);
            return this.formatReturnData(data);
        } catch (Exception e) {
            logger.error("GeosoundController-getEnergyData:", e);
            return this.formatReturnData(e.getMessage());
        } catch (Throwable throwable) {
            logger.error("GeosoundController-getEnergyData:", throwable);
            return this.formatReturnData(throwable.getMessage());
        }
    }

    /**
     * @Description: 大能量地音事件
     * @Param: [params, request, response]
     * @return: java.util.Map<java.lang.String   ,   java.lang.Object>
     * @Author: ChengQi
     * @Date: 2018/12/23
     */
    @RequestMapping("/largeEnergy") public Map<String, Object> largeEnergy(@RequestParam Map<String, Object> params,
        HttpServletRequest request, HttpServletResponse response) {
        try {
            Map<String, Object> data = new HashMap<String, Object>();
            // 矿区id
            String mineId = DataConversionUtil.getStrFromMap("mineId", params);

            String equipmentId = DataConversionUtil.getStrFromMap("equipmentId", params);
            // 开始时间
            String startTime = DataConversionUtil.getStrFromMap("startTime", params);

            if (StringUtils.isBlank(mineId) || StringUtils.isBlank(equipmentId) || StringUtils.isBlank(startTime)) {
                return this.formatReturnData("缺少参数");
            }
            if (!CheckUtils.isValidDate(startTime, "yyyy-MM-dd HH:mm:ss")) {
                return this.formatReturnData("日期格式不正确");
            }
            // 结束时间
            String defaultEndTime = DateUtils.getCurrentTime("yyyy-MM-dd HH:mm:ss");
            String endTime = DataConversionUtil.getStrFromMapOrSetDefaultValue("endTime", defaultEndTime, params);

            startTime = DateUtils.getBeforeDayDate(-30, startTime, "yyyy-MM-dd HH:mm:ss");

            List<Map<String, Object>> results =
                geoSoundService.queryWeblargeEnergy(mineId, equipmentId, startTime, endTime);
            data.put("list", results);
            return this.formatReturnData(data);
        } catch (Exception e) {
            logger.error("MicroseismController-microseismRealTime:", e);
            return this.formatReturnData(e.getMessage());
        } catch (Throwable throwable) {
            logger.error("MicroseismController-microseismRealTime:", throwable);
            return this.formatReturnData(throwable.getMessage());
        }
    }

    /**
     * @Description: 能量平均值
     * @Param: [params, request, response]
     * @return: java.util.Map<java.lang.String                               ,                               java.lang.Object>
     * @Author: ChengQi
     * @Date: 2018/12/23
     */
    @RequestMapping("/avgEmergoa") public Map<String, Object> avgEmergoa(@RequestParam Map<String, Object> params,
        HttpServletRequest request, HttpServletResponse response) {
        try {
            Map<String, Object> data = new HashMap<String, Object>();
            // 矿区id
            String mineId = DataConversionUtil.getStrFromMap("mineId", params);

            String equipmentId = DataConversionUtil.getStrFromMap("equipmentId", params);
            // 开始时间
            String startTime = DataConversionUtil.getStrFromMap("startTime", params);

            if (StringUtils.isBlank(mineId) || StringUtils.isBlank(equipmentId) || StringUtils.isBlank(startTime)) {
                return this.formatReturnData("缺少参数");
            }
            if (!CheckUtils.isValidDate(startTime, "yyyy-MM-dd HH:mm:ss")) {
                return this.formatReturnData("日期格式不正确");
            }
            // 结束时间
            String defaultEndTime = DateUtils.getCurrentTime("yyyy-MM-dd HH:mm:ss");
            String endTime = DataConversionUtil.getStrFromMapOrSetDefaultValue("endTime", defaultEndTime, params);
            //单位时间
            String unitTime = DataConversionUtil.getStrFromMapOrSetDefaultValue("timeSpan", "3", params);
            //时间间隔
            String interval = DataConversionUtil.getStrFromMapOrSetDefaultValue("interval", "6", params);

            data.put("total", geoSoundService
                .countCalEmergoa(mineId, equipmentId, startTime, endTime, Integer.parseInt(unitTime),
                    Integer.parseInt(interval)));
            String sizeStr = params.containsKey("size") ? params.get("size").toString() : "10000";
            sizeStr = StringUtils.isNotBlank(sizeStr) ? sizeStr : "10000";
            //int size = Integer.parseInt(sizeStr);
            int size = 10000;
            List<Map<String, Object>> results = geoSoundService
                .queryCalEmergoa(mineId, equipmentId, startTime, endTime, Integer.parseInt(unitTime),
                    Integer.parseInt(interval), size);
            data.put("list", results);
            return this.formatReturnData(data);
        } catch (Exception e) {
            logger.error("MicroseismController-microseismRealTime:", e);
            return this.formatReturnData(e.getMessage());
        } catch (Throwable throwable) {
            logger.error("MicroseismController-microseismRealTime:", throwable);
            return this.formatReturnData(throwable.getMessage());
        }
    }

    /**
     * @Description: 获取脉冲数据
     * @Param: [params, request, response]
     * @return: java.util.Map<java.lang.String                               ,                               java.lang.Object>
     * @Author: ChengQi
     * @Date: 2018/12/23
     */
    @RequestMapping("/getPulse") public Map<String, Object> getPulse(@RequestParam Map<String, Object> params,
        HttpServletRequest request, HttpServletResponse response) {
        try {
            Map<String, Object> data = new HashMap<String, Object>();

            // 矿区id
            String mineId = DataConversionUtil.getStrFromMap("mineId", params);

            String equipmentId = DataConversionUtil.getStrFromMap("equipmentId", params);
            // 开始时间
            String startTime = DataConversionUtil.getStrFromMap("startTime", params);

            if (StringUtils.isBlank(mineId) || StringUtils.isBlank(equipmentId) || StringUtils.isBlank(startTime)) {
                return this.formatReturnData("缺少参数");
            }
            if (!CheckUtils.isValidDate(startTime, "yyyy-MM-dd HH:mm:ss")) {
                return this.formatReturnData("日期格式不正确");
            }

            // 结束时间
            String defaultEndTime = DateUtils.getCurrentTime("yyyy-MM-dd HH:mm:ss");
            String endTime = DataConversionUtil.getStrFromMapOrSetDefaultValue("endTime", defaultEndTime, params);
            //单位时间
            String unitTime = DataConversionUtil.getStrFromMapOrSetDefaultValue("timeSpan", "10", params);
            int timeSpan = Integer.parseInt(unitTime);
            String nStr = DataConversionUtil.getStrFromMapOrSetDefaultValue("n", "6", params);
            int n = Integer.parseInt(nStr);
            data.put("total", geoSoundService.countCalPulse(mineId, equipmentId, startTime, endTime, timeSpan, n));

            String sizeStr = params.containsKey("size") ? params.get("size").toString() : "10000";
            sizeStr = StringUtils.isNotBlank(sizeStr) ? sizeStr : "10000";
            //int size = Integer.parseInt(sizeStr);
            int size = 10000;
            List<Map<String, Object>> results =
                geoSoundService.queryCalPulse(mineId, equipmentId, startTime, endTime, timeSpan, n, size);
            data.put("list", results);
            return this.formatReturnData(data);
        } catch (Exception e) {
            logger.error("MicroseismController-microseismRealTime:", e);
            return this.formatReturnData(e.getMessage());
        } catch (Throwable throwable) {
            logger.error("MicroseismController-microseismRealTime:", throwable);
            return this.formatReturnData(throwable.getMessage());
        }
    }


    /**
     * 能量偏差
     *
     * @param params
     * @param request
     * @param response
     * @return
     */
    @RequestMapping("/energyDeviation") public Map<String, Object> energyDeviation(
        @RequestParam Map<String, Object> params, HttpServletRequest request, HttpServletResponse response) {
        try {
            Map<String, Object> data = new HashMap<String, Object>();

            // 矿区id
            String mineId = DataConversionUtil.getStrFromMap("mineId", params);

            String equipmentId = DataConversionUtil.getStrFromMap("equipmentId", params);
            // 开始时间
            String startTime = DataConversionUtil.getStrFromMap("startTime", params);
            //单位时间
            String unitTime = DataConversionUtil.getStrFromMapOrSetDefaultValue("timeSpan", "3", params);
            //时间间隔
            String interval = DataConversionUtil.getStrFromMapOrSetDefaultValue("interval", "6", params);
            if (StringUtils.isBlank(mineId) || StringUtils.isBlank(equipmentId) || StringUtils.isBlank(startTime)) {
                return this.formatReturnData("缺少参数");
            }
            if (!CheckUtils.isValidDate(startTime, "yyyy-MM-dd HH:mm:ss")) {
                return this.formatReturnData("日期格式不正确");
            }
            // 结束时间
            String defaultEndTime = DateUtils.getCurrentTime("yyyy-MM-dd HH:mm:ss");
            String endTime = DataConversionUtil.getStrFromMapOrSetDefaultValue("endTime", defaultEndTime, params);

            data.put("total", geoSoundService
                .countCalEmergoa(mineId, equipmentId, startTime, endTime, Integer.parseInt(unitTime),
                    Integer.parseInt(interval)));
            String sizeStr = params.containsKey("size") ? params.get("size").toString() : "10000";
            sizeStr = StringUtils.isNotBlank(sizeStr) ? sizeStr : "10000";
            //int size = Integer.parseInt(sizeStr);
            int size = 10000;
            List<Map<String, Object>> results = geoSoundService
                .queryCalEmergoa(mineId, equipmentId, startTime, endTime, Integer.parseInt(unitTime),
                    Integer.parseInt(interval), size);
            data.put("list", results);
            return this.formatReturnData(data);
        } catch (Exception e) {
            logger.error("MicroseismController-microseismRealTime:", e);
            return this.formatReturnData(e.getMessage());
        } catch (Throwable throwable) {
            logger.error("MicroseismController-microseismRealTime:", throwable);
            return this.formatReturnData(throwable.getMessage());
        }
    }

    /**
     * 每日
     *
     * @param params
     * @param request
     * @param response
     * @return
     */
    @RequestMapping("/daily") public Map<String, Object> daily(@RequestParam Map<String, Object> params,
        HttpServletRequest request, HttpServletResponse response) {
        try {
            Map<String, Object> data = new HashMap<String, Object>();

            // 矿区id
            String mineId = DataConversionUtil.getStrFromMap("mineId", params);

            String equipmentId = DataConversionUtil.getStrFromMap("equipmentId", params);
            // 开始时间
            String startTime = DataConversionUtil.getStrFromMap("startTime", params);

            if (StringUtils.isBlank(mineId) || StringUtils.isBlank(equipmentId) || StringUtils.isBlank(startTime)) {
                return this.formatReturnData("缺少参数");
            }
            if (!CheckUtils.isValidDate(startTime, "yyyy-MM-dd HH:mm:ss")) {
                return this.formatReturnData("日期格式不正确");
            }
            // 结束时间
            String defaultEndTime = DateUtils.getCurrentTime("yyyy-MM-dd HH:mm:ss");
            String endTime = DataConversionUtil.getStrFromMapOrSetDefaultValue("endTime", defaultEndTime, params);
            //startTime = DateUtils.getBeforeDayDate(-30, startTime, "yyyy-MM-dd HH:mm:ss");
            data.put("total", geoSoundService.countDaily(mineId, equipmentId, startTime, endTime));
            String sizeStr = params.containsKey("size") ? params.get("size").toString() : "10000";
            sizeStr = StringUtils.isNotBlank(sizeStr) ? sizeStr : "10000";
            //int size = Integer.parseInt(sizeStr);
            int size = 10000;

            List<Map<String, Object>> results = geoSoundService.daily(mineId, equipmentId, startTime, endTime, size);
            data.put("list", results);
            return this.formatReturnData(data);
        } catch (Exception e) {
            logger.error("MicroseismController-microseismRealTime:", e);
            return this.formatReturnData(e.getMessage());
        } catch (Throwable throwable) {
            logger.error("MicroseismController-microseismRealTime:", throwable);
            return this.formatReturnData(throwable.getMessage());
        }
    }

    /**
     * @Description: 脉冲因子
     * @Param: [params, request, response]
     * @return: java.util.Map<java.lang.String       ,       java.lang.Object>
     * @Author: ChengQi
     * @Date: 2019/2/20
     */
    @RequestMapping("/pulseFactor") public Map<String, Object> pulseFactor(@RequestParam Map<String, Object> params,
        HttpServletRequest request, HttpServletResponse response) {
        try {
            Map<String, Object> data = new HashMap<String, Object>();

            // 矿区id
            String mineId = DataConversionUtil.getStrFromMap("mineId", params);

            String equipmentId = DataConversionUtil.getStrFromMap("equipmentId", params);
            // 开始时间
            String startTime = DataConversionUtil.getStrFromMap("startTime", params);

            if (StringUtils.isBlank(mineId) || StringUtils.isBlank(equipmentId) || StringUtils.isBlank(startTime)) {
                return this.formatReturnData("缺少参数");
            }
            if (!CheckUtils.isValidDate(startTime, "yyyy-MM-dd HH:mm:ss")) {
                return this.formatReturnData("日期格式不正确");
            }
            // 结束时间
            String defaultEndTime = DateUtils.getCurrentTime("yyyy-MM-dd HH:mm:ss");
            String endTime = DataConversionUtil.getStrFromMapOrSetDefaultValue("endTime", defaultEndTime, params);

            //单位时间
            String unitTime = DataConversionUtil.getStrFromMapOrSetDefaultValue("timeSpan", "10", params);
            int timeSpan = Integer.parseInt(unitTime);

            String nStr = DataConversionUtil.getStrFromMapOrSetDefaultValue("n", "6", params);
            int n = Integer.parseInt(nStr);

            data.put("total", geoSoundService.countCalPulse(mineId, equipmentId, startTime, endTime, timeSpan, n));

            String sizeStr = params.containsKey("size") ? params.get("size").toString() : "10000";
            sizeStr = StringUtils.isNotBlank(sizeStr) ? sizeStr : "10000";
            //int size = Integer.parseInt(sizeStr);
            int size = 10000;
            List<Map<String, Object>> results =
                geoSoundService.queryCalPulse(mineId, equipmentId, startTime, endTime, timeSpan, n, size);
            data.put("list", results);
            return this.formatReturnData(data);
        } catch (Exception e) {
            logger.error("MicroseismController-microseismRealTime:", e);
            return this.formatReturnData(e.getMessage());
        } catch (Throwable throwable) {
            logger.error("MicroseismController-microseismRealTime:", throwable);
            return this.formatReturnData(throwable.getMessage());
        }
    }


    /**
     * 脉冲偏差
     *
     * @param params
     * @param request
     * @param response
     * @return
     */
    @RequestMapping("/pulseDeviation") public Map<String, Object> pulseDeviation(
        @RequestParam Map<String, Object> params, HttpServletRequest request, HttpServletResponse response) {
        try {
            Map<String, Object> data = new HashMap<String, Object>();

            // 矿区id
            String mineId = DataConversionUtil.getStrFromMap("mineId", params);

            String equipmentId = DataConversionUtil.getStrFromMap("equipmentId", params);
            // 开始时间
            String startTime = DataConversionUtil.getStrFromMap("startTime", params);

            if (StringUtils.isBlank(mineId) || StringUtils.isBlank(equipmentId) || StringUtils.isBlank(startTime)) {
                return this.formatReturnData("缺少参数");
            }
            if (!CheckUtils.isValidDate(startTime, "yyyy-MM-dd HH:mm:ss")) {
                return this.formatReturnData("日期格式不正确");
            }

            startTime = DateUtils.getBeforeDayDate(-30, startTime, "yyyy-MM-dd HH:mm:ss");
            // 结束时间
            String defaultEndTime = DateUtils.getCurrentTime("yyyy-MM-dd HH:mm:ss");
            String endTime = DataConversionUtil.getStrFromMapOrSetDefaultValue("endTime", defaultEndTime, params);

            //单位时间
            String unitTime = DataConversionUtil.getStrFromMapOrSetDefaultValue("timeSpan", "10", params);
            int timeSpan = Integer.parseInt(unitTime);

            String nStr = DataConversionUtil.getStrFromMapOrSetDefaultValue("n", "24", params);
            int n = Integer.parseInt(nStr);
            data.put("total", geoSoundService.countCalPulse(mineId, equipmentId, startTime, endTime, timeSpan, n));
            String sizeStr = params.containsKey("size") ? params.get("size").toString() : "10000";
            sizeStr = StringUtils.isNotBlank(sizeStr) ? sizeStr : "10000";
            //int size = Integer.parseInt(sizeStr);
            int size = 10000;
            List<Map<String, Object>> results =
                geoSoundService.queryCalPulse(mineId, equipmentId, startTime, endTime, timeSpan, n, size);
            data.put("list", results);
            return this.formatReturnData(data);
        } catch (Exception e) {
            logger.error("MicroseismController-microseismRealTime:", e);
            return this.formatReturnData(e.getMessage());
        } catch (Throwable throwable) {
            logger.error("MicroseismController-microseismRealTime:", throwable);
            return this.formatReturnData(throwable.getMessage());
        }
    }


    /**
     * 每日脉冲偏差高值总数
     *
     * @param params
     * @param request
     * @param response
     * @return
     */
    @RequestMapping("/dailyPulseDeviationHighValue") public Map<String, Object> dailyPulseDeviationHighValue(
        @RequestParam Map<String, Object> params, HttpServletRequest request, HttpServletResponse response) {
        try {
            Map<String, Object> data = new HashMap<String, Object>();

            // 矿区id
            String mineId = DataConversionUtil.getStrFromMap("mineId", params);

            String equipmentId = DataConversionUtil.getStrFromMap("equipmentId", params);
            // 开始时间
            String startTime = DataConversionUtil.getStrFromMap("startTime", params);

            if (StringUtils.isBlank(mineId) || StringUtils.isBlank(equipmentId) || StringUtils.isBlank(startTime)) {
                return this.formatReturnData("缺少参数");
            }
            if (!CheckUtils.isValidDate(startTime, "yyyy-MM-dd HH:mm:ss")) {
                return this.formatReturnData("日期格式不正确");
            }
            // 结束时间
            String defaultEndTime = DateUtils.getCurrentTime("yyyy-MM-dd HH:mm:ss");
            String endTime = DataConversionUtil.getStrFromMapOrSetDefaultValue("endTime", defaultEndTime, params);

            String aSr = DataConversionUtil.getStrFromMapOrSetDefaultValue("a", "2", params);
            int a = Integer.parseInt(aSr);

            data.put("total", geoSoundService.countDaily(mineId, equipmentId, startTime, endTime));
            String sizeStr = params.containsKey("size") ? params.get("size").toString() : "10000";
            sizeStr = StringUtils.isNotBlank(sizeStr) ? sizeStr : "10000";
            //int size = Integer.parseInt(sizeStr);
            int size = 10000;

            List<Map<String, Object>> results = geoSoundService.daily(mineId, equipmentId, startTime, endTime, size);
            data.put("list", results);
            return this.formatReturnData(data);
        } catch (Exception e) {
            logger.error("MicroseismController-microseismRealTime:", e);
            return this.formatReturnData(e.getMessage());
        } catch (Throwable throwable) {
            logger.error("MicroseismController-microseismRealTime:", throwable);
            return this.formatReturnData(throwable.getMessage());
        }
    }


    /**
     * @Description: 综合预警
     * @Param: [params, request, response]
     * @return: java.util.Map<java.lang.String       ,       java.lang.Object>
     * @Author: ChengQi
     * @Date: 2019/1/3
     */
    @RequestMapping("/comprehensiveWarning") public Map<String, Object> comprehensiveWarning(
        @RequestParam Map<String, Object> params, HttpServletRequest request, HttpServletResponse response) {
        try {
            Map<String, Object> data = new HashMap<String, Object>();

            // 矿区id
            String mineId = DataConversionUtil.getStrFromMap("mineId", params);

            //String deviceId = DataConversionUtil.getStrFromMap("equipmentId", params);

            // 开始时间
            String startTime = DataConversionUtil.getStrFromMap("startTime", params);

            if (StringUtils.isBlank(mineId) || StringUtils.isBlank(startTime)) {
                return this.formatReturnData("缺少参数");
            }
            if (!CheckUtils.isValidDate(startTime, "yyyy-MM-dd HH:mm:ss")) {
                return this.formatReturnData("日期格式不正确");
            }
            // 结束时间
            String defaultEndTime = DateUtils.getCurrentTime("yyyy-MM-dd HH:mm:ss");
            String endTime = DataConversionUtil.getStrFromMapOrSetDefaultValue("endTime", defaultEndTime, params);

            Map<String, Object> results = geoSoundService.comprehensiveWarning(mineId, startTime, endTime);
            data.put("list", results);
            return this.formatReturnData(data);
        } catch (Exception e) {
            logger.error("MicroseismController-microseismRealTime:", e);
            return this.formatReturnData(e.getMessage());
        } catch (Throwable throwable) {
            logger.error("MicroseismController-microseismRealTime:", throwable);
            return this.formatReturnData(throwable.getMessage());
        }
    }

    @RequestMapping("/pluseAndEnergy")
    public Map<String, Object> pluseAndEnergy(@RequestParam Map<String, Object> params,
                                              HttpServletRequest request,
                                              HttpServletResponse response) {
        try {
            Map<String, Object> data = new HashMap<String, Object>();

            // 矿区id
            String mineId = DataConversionUtil.getStrFromMap("mineId", params);

            String equipmentId = DataConversionUtil.getStrFromMap("equipmentId", params);
            // 开始时间
            String startTime = DataConversionUtil.getStrFromMap("startTime", params);

            if (StringUtils.isBlank(mineId) || StringUtils.isBlank(equipmentId) || StringUtils.isBlank(startTime)) {
                return this.formatReturnData("缺少参数");
            }
            if (!CheckUtils.isValidDate(startTime, "yyyy-MM-dd HH:mm:ss")) {
                return this.formatReturnData("日期格式不正确");
            }

            // 结束时间
            String defaultEndTime = DateUtils.getCurrentTime("yyyy-MM-dd HH:mm:ss");
            String endTime = DataConversionUtil.getStrFromMapOrSetDefaultValue("endTime", defaultEndTime, params);
            //单位时间
            String unitTime = DataConversionUtil.getStrFromMapOrSetDefaultValue("timeSpan", "10", params);
            int timeSpan = Integer.parseInt(unitTime);
            String nStr = DataConversionUtil.getStrFromMapOrSetDefaultValue("n", "6", params);
            int n = Integer.parseInt(nStr);
            //data.put("total", geoSoundService.countCalPulse(mineId, equipmentId, startTime, endTime, timeSpan, n));

            String sizeStr = params.containsKey("size") ? params.get("size").toString() : "10000";
            sizeStr = StringUtils.isNotBlank(sizeStr) ? sizeStr : "10000";
            //int size = Integer.parseInt(sizeStr);
            int size = 10000;
            List<Map<String, Object>> results =
                    geoSoundService.queryPluseAndEnergy(mineId, equipmentId, startTime, endTime, timeSpan, n, size);
            data.put("list", results);
            data.put("total", results.size());
            return this.formatReturnData(data);
        } catch (Exception e) {
            logger.error("MicroseismController-microseismRealTime:", e);
            return this.formatReturnData(e.getMessage());
        } catch (Throwable throwable) {
            logger.error("MicroseismController-microseismRealTime:", throwable);
            return this.formatReturnData(throwable.getMessage());
        }
    }

}
